package com.lanqiao.gxnushop.mapper;

import com.lanqiao.gxnushop.entity.Products;
import com.lanqiao.gxnushop.util.StringUtil;
import com.lanqiao.gxnushop.valueObject.ProductsF;

public class ProductsMapperProvide {
    public String getProductsListSql(Products products){
        StringBuffer sb = new StringBuffer("select * from products where storeId = #{storeId}");
        if(StringUtil.isNotEmpty(products.getName())&&products.getName()!=""){
            sb.append(" and name like concat('%',#{name},'%')");
        }
        if(StringUtil.isNotEmpty(products.getState())&&products.getState()!=""){
            sb.append(" and state = #{state}");
        }
        if(StringUtil.isNotEmpty(products.getGoodsCategory())&&products.getGoodsCategory()!=""){
            sb.append(" and goodsCategory like concat('%',#{goodsCategory},'%')");
        }
        String sql = sb.toString();
        return sql;
    }

    public String getStockSql(ProductsF productsF){
        StringBuffer sb = new StringBuffer("select DISTINCT products.*\n" +
                "from products join stores on (stores.storeId = products.storeId) \n" +
                "join sellers on (sellers.sellerId = stores.sellerId)\n" +
                "where sellers.sellerId = #{sellerId}");
        if(StringUtil.isNotEmpty(productsF.getName())&&productsF.getName()!=""){
            sb.append("  and products.name like concat('%',#{name},'%')");
        }
        if(StringUtil.isNotEmpty(productsF.getState())&&productsF.getState()!=""){
            sb.append("  and products.state = #{state}");
        }
        if (StringUtil.isNotEmpty(productsF.getGoodsCategory())&&productsF.getGoodsCategory()!=""){
            sb.append("  and products.goodsCategory like concat('%',#{goodsCategory},'%')");
        }
        String sql = sb.toString();
        return sql;
    }

}
